﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace Cocon90.Lib.Dal.Utility
{
    /// <summary>
    /// Oledb数据库操作实例
    /// </summary>
    public class OledbDataHelper : DataHelper
    {
        #region DataHelper 成员
        public override DbCommand createCommond(string tsql, CommandType commandType, params System.Data.Common.DbParameter[] paramKeyAndValue)
        {
            using (OleDbConnection conn = new OleDbConnection(GetConnectionString))
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand(tsql, conn);
                cmd.CommandText = tsql;
                cmd.CommandType = commandType;
                foreach (var para in paramKeyAndValue)
                {
                    cmd.Parameters.Add(para);
                }
                conn.Close();
                return cmd;
            }
        }
        public override DbDataAdapter createDataAdapter(System.Data.Common.DbCommand selectCmd)
        {
            OleDbDataAdapter dap = new OleDbDataAdapter((OleDbCommand)selectCmd);
            return dap;
        }
        public override DbParameter createParameter(string key, object value)
        {
            OleDbParameter para = new OleDbParameter(key, value);
            return para;
        }
        #endregion
    }

}
